Most of the plumbing required for connecting and manipulating circuits is completed, as well as a rough but working implementation of linear DC operating point analysis (linearly controlled voltage and current sources aren't implemented yet, and there are still some unhandled cases where an invalid circuit can break the solver).
An example of a simple circuit that currently does not work is in "operating point test 2" in tests/op.jl.
ode
solver functionsWith the above features implemented, various circuits will be simulated, and the results compared with both hand analysis and SPICE simulations.
In [7]:
include("SimpleCircuits.jl")
using SimpleCircuits
Consider the following circuit:
Solving the circuit here is equivalent to solving a system with two unknowns, $v_1$ and $v_2$. The linear system can be obtained using Kirchhoff's Current Law at node 2 and the definition of a voltage source at node 1. Using $V = IR$ and summing the currents at node 2:
$$ \frac{v_1 - v_2} {5000} + \frac {0 - v_2} {10000} = 0 \implies \frac{1}{5000} v_1 - (\frac{1}{5000} + \frac{1}{10000}) v_2 = 0$$And at node 1:
$$ v_1 = v_{GND} + 5 = 5 $$This process for constructing the linear system of equations can be generalized for any linear circuit. Analysis with the current implementation (see op.jl
for details):
In [2]:
# testing linear DC operating point
circ = Circuit()
# create the components
r1 = Resistor(5e+3)
r2 = Resistor(10e+3)
v_DC = DCVoltageSource(5.)
# connect the components, and specify ground (reference voltage)
connect!(circ, v_DC.pHigh, r1.p1, "Node 1")
connect!(circ, r1.p2, r2.p1, "Node 2")
connect!(circ, r2.p2, v_DC.pLow)
connect!(circ, circ.gnd, v_DC.pLow)
# compute the DC operating point
node_voltages = op(circ)
Out[2]: